﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WB.Entity;
using WB.DaoHelper;
using WB.Library;
using Bussiness.Manager;
public partial class Admin_Product_ProductList : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadCombo();
            LoadData();
        }
    }

    void LoadCombo()
    {
     //   ddlCategory.DataSource = CategoryDao.Instants().GetAll();
        DataTable tbl = CmsCategoryManager.CreateInstant().GetCategoryTreeByLang("PROD", "vi-VN");
        ddlCategory.DataSource = tbl;
        ddlCategory.DataTextField = "CatName";
        ddlCategory.DataValueField = "Id";
        ddlCategory.DataGroupField = "ParentName";
        ddlCategory.DataBind();
    }

    void LoadData()
    {
       // PagedData page = ProductsDao.Instants().GetSearch(txtProductName.Text.Trim(), ddlCategory.Text, ucPager1.CurrentPageIndex);
        //rep.DataSource = page.DataSource;
        rep.DataSource = CmsProductsManager.CreateInstant().Search(txtProductName.Text.Trim(), FGuid.ToGuid(ddlCategory.SelectedValue), "vi-VN");
        rep.DataBind();
     //   ucPager1.LoadPageLink(ucPager1.CurrentPageIndex);
    }

    public void OnChangePagging(object sender, PaggingEventArgs e)
    {
        LoadData();
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        LoadData();
    }

    protected void rep_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "del":
                ProductsEntity ob = ProductsDao.Instants().SelectOne(FGuid.ToGuid(e.CommandArgument.ToString()));
                if (ob != null)
                {
                    ob.IsDeleted = true;
                    ob.UpdatedBy = Util.CurrentUserName;
                    ob.UpdatedDate = DateTime.Now;
                    ProductsDao.Instants().Update(ob);

                    LoadData();
                }
                break;
        }
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Response.Redirect("?control=addpro");
    }
}
